package com.linwen.dataStructure.queue;
/*
 * 循环队列
 * */
public class MyQueue {
	private int[] array;
	private int font;
	private int end;
	
	//无参构造方法
	public MyQueue() {
		array = new int [4];
		font = 0;
		end = 0;
	}
	//有参构造方法
	public MyQueue(int size) {
		array = new int [size];
		font = 0;
		end = 0;
	}
	//插入队列（队列尾）
	public boolean insert(int value) throws Exception {
		//队满
		if((end+1)%array.length==font) {
			//return false;
			throw new Exception("队列已满");
		}
		array[end] = value;
		end = (end+1)%array.length;
		return true;
	}
	//出队
	public int  remove() throws Exception {
		//空队列时
		if(end==font) {
			//return -1;
			throw new Exception("队列为空");
		}
		int temp = array[font];
		font = (font+1)%array.length;
		return temp;
	
	}
	//查看队列头
	public int peek() {
		return array[font];
	}
	//判断是否为空
	public boolean isEmpty() {
		return end==font;
	}
	//判断是否满了
	public boolean isFull() {
		return  ((end+1)%array.length)==font;
	}
	//toString
	public String toString() {
		String str = "";
		for(int i:array) {
			str = str+i+" ";
		}
		return str;
	}
	
	
	
	
}
